package me.xue.communityhealth.service;

import me.xue.communityhealth.model.Registration;
import me.xue.communityhealth.repo.RegistrationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class RegistrationService implements BaseService<Registration, Integer> {

    private final RegistrationRepository registrationRepository;

    @Autowired
    public RegistrationService(RegistrationRepository registrationRepository) {
        this.registrationRepository = registrationRepository;
    }

    @Override
    public int save(Registration registration) {
        return registrationRepository.insert(registration);
    }

    @Override
    public int update(Registration registration) {
        return registrationRepository.update(registration);
    }

    @Override
    public int delete(Integer which) {
        return (which == null || which < 0) ? 0 : registrationRepository.delete(which);
    }

    @Override
    public List<Registration> findAll() {
        return registrationRepository.findAll();
    }

    public Registration findRegistrationByName(String name) {
        return StringUtils.isEmpty(name) ? null : registrationRepository.findByName(name);
    }

    public List<Registration> findAllRegistrationByName(String name) {
        return StringUtils.isEmpty(name) ? null : registrationRepository.findAllByName(name);
    }
}
